# -*- coding: utf-8 -*-
import datetime as datetime
import pandas as pd
import numpy as np
import datetime
import time
from sqlalchemy import create_engine

engine = create_engine('mysql+pymysql://weex:123qwe!!@onlyreaddb.cibzepqty2kl.ap-northeast-1.rds.amazonaws.com:3306/trade_history?charset=utf8')
#engine = engine = create_engine('mysql+pymysql://PP:weex123@192.168.0.196:3306/trade_history?charset=utf8')


sql1 = 'SELECT * FROM order_history_37 WHERE ;'
sql2 = 'SELECT price, amount FROM order_history_37 WHERE user_id=78337 and market= "DASHBTC" and side=2;'
##1 sell 2 buy


if __name__ == '__main__':
    resufl = []
    df = pd.DataFrame()
    dfname = locals()

    order_sell = pd.read_sql_query(sql1, engine)
    order_sell.columns = ['price_sell', 'amount_sell']

    order_buy = pd.read_sql_query(sql2, engine)
    order_buy.columns = ['price_buy', 'amount_buy']

    #order_all = pd.concat([order_sell, order_buy], axis=1)

    for index, row in order_sell.iterrows():
        #print(row.index,row["price_sell"], row["amount_sell"])
        data = order_buy[(order_buy['price_buy']== row["price_sell"]) & (order_buy['amount_buy'] == row["amount_sell"])].index
        if len(data) == 1:
            order_buy.drop(data, inplace = True)
            order_sell.drop(index, inplace = True)
            print(data)

    order_sell.to_csv("/Users/fiery/Desktop/order_DASHBTC_sell.csv")
    order_buy.to_csv("/Users/fiery/Desktop/order_DASHBTC_buy.csv")

    #list_100_id.to_excel("/Users/fiery/Desktop/trade_award.xls", sheet_name = '100award')



